
package kaizen.com;

import java.io.IOException;
import java.io.PrintStream;

import java.util.Vector;

import kaizen.jdbc.cMgr;
import kaizen.jdbc.dbRecord;

// Referenced classes of package kaizen.com:
//            Error, Log

public final class errMgr
{

  public static int display(int i, int j, String s, String s1)
  {
    int k = searchError(i, j);
    if (k == 0)
      if (j > 0)
      {
        String s2 = 
          "SELECT title, msg, opts, count, def FROM msg_language WHERE type = " + 
          i + " AND number = " + j + " AND language = '" + s + "'";
        try
        {
          cMgr.executeQuery("gerentia", "err01", s2);
        } catch (IOException e)
        {
          // TODO
        }
        cMgr.Next("gerentia", "err01");
        dbRecord dbrecord = cMgr.getRecord("gerentia", "err01");
        String s3 = dbrecord.getField(1);
        String s4 = dbrecord.getField(2);
        String s5 = dbrecord.getField(3);
        int l = (new Integer(dbrecord.getField(4))).intValue();
        int i1 = (new Integer(dbrecord.getField(5))).intValue();
        String as1[] = createArray(s5, l, "|");
        vError.addElement(new Error(i, j, s3, s4, as1, l, i1));
        k = vError.size();
      } else
      {
        String as[] =
        { "OK" };
        vError.addElement(new Error(i, j, s1, "Initilization", as, 1, 1));
        k = vError.size();
      }
    if (k > 0)
    {
      Error error = (Error)vError.elementAt(k - 1);
      Log.writeErr(error.getTitle() + " " + error.getMessage());
      System.out.println(error.getTitle() + " " + error.getMessage());
    }
    return 0;
  }

  public static String[] createArray(String s, int i, String s1)
  {
    String as[] = new String[i];
    int j;
    for (j = 0; s.indexOf(s1) != -1; j++)
    {
      as[j] = s.substring(0, s.indexOf(s1));
      s = s.substring(s.indexOf(s1) + 1, s.length()).trim();
    }

    if (s.length() > 0)
      as[j] = s;
    return as;
  }

  public static int searchError(int i, int j)
  {
    int k = 0;
    Object obj = null;
    for (int l = 0; l < vError.size(); l++)
    {
      Error error = (Error)vError.elementAt(l);
      if (error.getType() != i || error.getNumber() != j)
        continue;
      k = l + 1;
      break;
    }

    return k;
  }

  public errMgr()
  {
  }

  private static Vector vError = new Vector();

}
